#include "BDTestBase.h"

DECLARE_TEST_VAR(Test_7)
{
	bool isIn = true;
	int outTimes = 0;
	int rocker1CenterX = 300;
	int rocker1CenterY = 100;
	int rocker2CenterX = 300;
	int rocker2CenterY = 500;
};

DECLARE_TEST_F(Test_7, BDTestBase)

DECLARE_EXAMPLE(Test_7)
{
	// 1. new shape
	AllocPainterParamShape(4);
	GetPainterParamShape(2)->set_type(PainterRefreshParam_Shape_ShapeType_SHAPE_CIRCLE);
	GetPainterParamShape(2)->mutable_circle()->set_x(TEST_VAR(rocker1CenterX));
	GetPainterParamShape(2)->mutable_circle()->set_y(TEST_VAR(rocker1CenterY));
	GetPainterParamShape(2)->mutable_circle()->set_r(20);
	GetPainterParamShape(2)->mutable_circle()->set_line_color(PainterRefreshParam_Shape_Color_COLOR_BLACK);
	GetPainterParamShape(2)->mutable_circle()->set_fill_color(PainterRefreshParam_Shape_Color_COLOR_RED);

	GetPainterParamShape(3)->set_type(PainterRefreshParam_Shape_ShapeType_SHAPE_CIRCLE);
	GetPainterParamShape(3)->mutable_circle()->set_x(TEST_VAR(rocker2CenterX));
	GetPainterParamShape(3)->mutable_circle()->set_y(TEST_VAR(rocker2CenterY));
	GetPainterParamShape(3)->mutable_circle()->set_r(20);
	GetPainterParamShape(3)->mutable_circle()->set_line_color(PainterRefreshParam_Shape_Color_COLOR_BLACK);
	GetPainterParamShape(3)->mutable_circle()->set_fill_color(PainterRefreshParam_Shape_Color_COLOR_YELLOW);

	GetPainterParamShape(0)->set_type(PainterRefreshParam_Shape_ShapeType_SHAPE_CIRCLE);
	GetPainterParamShape(0)->mutable_circle()->set_x(300);
	GetPainterParamShape(0)->mutable_circle()->set_y(300);
	GetPainterParamShape(0)->mutable_circle()->set_r(250);
	GetPainterParamShape(0)->mutable_circle()->set_line_color(PainterRefreshParam_Shape_Color_COLOR_BLACK);
	GetPainterParamShape(0)->mutable_circle()->set_fill_color(PainterRefreshParam_Shape_Color_COLOR_NONE);

	GetPainterParamShape(1)->set_type(PainterRefreshParam_Shape_ShapeType_SHAPE_CIRCLE);
	GetPainterParamShape(1)->mutable_circle()->set_x(300);
	GetPainterParamShape(1)->mutable_circle()->set_y(300);
	GetPainterParamShape(1)->mutable_circle()->set_r(150);
	GetPainterParamShape(1)->mutable_circle()->set_line_color(PainterRefreshParam_Shape_Color_COLOR_BLACK);
	GetPainterParamShape(1)->mutable_circle()->set_fill_color(PainterRefreshParam_Shape_Color_COLOR_NONE);

	// 2. calculate outTimes
	bool currentIsIn = BDTestUtils::Intersects(GetPainterParamShape(0)->mutable_circle()->x(), GetPainterParamShape(0)->mutable_circle()->y(), GetPainterParamShape(0)->mutable_circle()->r(),
												GetPainterParamShape(2)->mutable_circle()->x(), GetPainterParamShape(2)->mutable_circle()->y(), GetPainterParamShape(2)->mutable_circle()->r())
					&& !BDTestUtils::Contains(GetPainterParamShape(1)->mutable_circle()->x(), GetPainterParamShape(1)->mutable_circle()->y(), GetPainterParamShape(1)->mutable_circle()->r(),
												GetPainterParamShape(2)->mutable_circle()->x(), GetPainterParamShape(2)->mutable_circle()->y(), GetPainterParamShape(2)->mutable_circle()->r())
					&&	BDTestUtils::Intersects(GetPainterParamShape(0)->mutable_circle()->x(), GetPainterParamShape(0)->mutable_circle()->y(), GetPainterParamShape(0)->mutable_circle()->r(),
												GetPainterParamShape(3)->mutable_circle()->x(), GetPainterParamShape(3)->mutable_circle()->y(), GetPainterParamShape(3)->mutable_circle()->r())
					&& !BDTestUtils::Contains(GetPainterParamShape(1)->mutable_circle()->x(), GetPainterParamShape(1)->mutable_circle()->y(), GetPainterParamShape(1)->mutable_circle()->r(),
												GetPainterParamShape(3)->mutable_circle()->x(), GetPainterParamShape(3)->mutable_circle()->y(), GetPainterParamShape(3)->mutable_circle()->r());
	if (currentIsIn != TEST_VAR(isIn)) {
		if (currentIsIn == false) {
			TEST_VAR(outTimes)++;
		}
		TEST_VAR(isIn) = currentIsIn;
	}

	// 3. add param to QMap<QString,QString>
	AllocDetailParamItem(2);
	GetDetailParamItem(0)->set_key("Attention");
	ostringstream os0;
	os0 << m_iAttention;
	GetDetailParamItem(0)->set_value(os0.str());

	GetDetailParamItem(1)->set_key("Out Times");
	ostringstream os1;
	os1 << TEST_VAR(outTimes);
	GetDetailParamItem(1)->set_value(os1.str());

	// 4. change
	TEST_VAR(rocker1CenterX) += m_iRockerX1;
	TEST_VAR(rocker1CenterY) += m_iRockerY1;
	TEST_VAR(rocker2CenterX) += m_iRockerX2;
	TEST_VAR(rocker2CenterY) += m_iRockerY2;

	// 5. notice update ui
	Notify();
}
